#============ MAKE FILE for the SCsimulator
#
# This file creates the SCsimulator application and the build the test if
# the necessary framework is found.
# 
# Compiler defines:
#    on GCC:            -DGNUCXX
#    on VisualStudio:    -DMSVC
#    if logging enabled:    -DLOG4CPLUS_FOUND
#
    
project (hfsme)
cmake_minimum_required (VERSION 2.6)

IF("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 2.7)
	#For newer versions of Cmake set to convert all relative
	#paths to full paths
	cmake_policy(SET CMP0015 NEW)
endif ("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" GREATER 2.7)


set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${PROJECT_SOURCE_DIR}/cmake/")
include(InternalMacros)
include(FindPackageHandleStandardArgs)

#=================================== LIBRERIE ==================================
#set(Boost_USE_STATIC_LIBS        ON)
#set(Boost_USE_MULTITHREADED      ON)
#set(Boost_USE_STATIC_RUNTIME    OFF)
#find_package(Boost 1.34 REQUIRED COMPONENTS system prg_exec_monitor unit_test_framework)
#include_directories(${Boost_INCLUDE_DIRS})
#link_directories(${Boost_LIBRARY_DIRS})

#find_package(GMock)
#include_directories(${GMOCK_INCLUDE_DIRS})
#include_directories(/tmp/gmock-1.6.0)
#include_directories(/tmp/gmock-1.6.0/gtest)
#include_directories(/tmp/gmock-1.6.0/gtest/include)

#==================== SETUP THE COMPILER FLAGS ========================

if(CMAKE_COMPILER_IS_GNUCXX OR MINGW)    
    set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -std=c++0x -Wall -pedantic -g -W -D_REENTRANT -Wctor-dtor-privacy -Wnon-virtual-dtor -Wno-long-long -o0" )
endif(CMAKE_COMPILER_IS_GNUCXX OR MINGW)

if(WIN32) 
    #link delle winsock
    find_library(WSOCK32_LIBRARY wsock32)
    find_library(WS2_32_LIBRARY ws2_32)
    add_definitions(-D_WIN32_WINNT=0x0501)
    add_definitions(-D_CRT_SECURE_NO_WARNINGS -DWIN32_LEAN_AND_MEAN )
    #nascondi la console nella versione release per windows, si tratta di un opzione del linker
    set(CMAKE_EXE_LINKER_FLAGS_RELEASE " /SUBSYSTEM:WINDOWS")
endif(WIN32)


##process the configured header file
#configure_file(
#    "${PROJECT_SOURCE_DIR}/Include/NMBA_Protocol/ConfigOptions.h.in"
#    "${PROJECT_BINARY_DIR}/ConfigOptions.h"
#    )
include_directories("${PROJECT_SOURCE_DIR}/include")



#== add my includes
#set(NMBA_protocol_INCLUDE "${PROJECT_SOURCE_DIR}/Include")
include_directories(${PROJECT_SOURCE_DIR})
#link_directories(${NMBA_protocol_BINARY_DIR}/lib)

if(NOT DEFINED no-test)
    message(STATUS "Boost test found, building tests")
    
    ENABLE_TESTING()    
    set(CMAKE_CTEST_COMMAND ctest -V)
    add_custom_target(check COMMAND ${CMAKE_CTEST_COMMAND})    
    set(UNITTESTS_ENABLED true)
    add_subdirectory(contrib/gmock)    
    include_directories(${GMOCK_INCLUDE_DIRS})
    message(INFO ${GMOCK_INCLUDE_DIRS})    
    add_subdirectory (tests)
endif(NOT DEFINED no-test)



add_subdirectory (src)
#incrementa il build number
#if(WIN32)
#    ADD_CUSTOM_COMMAND(TARGET NMBA_Protocol POST_BUILD COMMAND "build_inc.bat")
#elseif(UNIX)
#endif(WIN32)

# add a target to generate API documentation with Doxygen
#find_package(Doxygen)

#if(DOXYGEN_FOUND)
#    message(STATUS "Doxygen found, type make doc to generate the documentation")
#    add_custom_target(doc
#        ${DOXYGEN_EXECUTABLE} "${PROJECT_SOURCE_DIR}/SCsimulator.doxyfile"
#        WORKING_DIRECTORY ${PROJECT_SOURCE_DIR}
#        COMMENT "Generating API documentation with Doxygen" VERBATIM
#    )
#endif(DOXYGEN_FOUND)


###======================== PACKAGING========================
##this create the install package with only for WINDOWS con MINGW
#
#
##install definitions for the required files
#install(DIRECTORY MessageLists DESTINATION . COMPONENT base FILES_MATCHING PATTERN "*.xml")
#install(FILES "tracer_config.xml" DESTINATION . COMPONENT base )
#
##install system libraries
#install(FILES "${QT_LIBRARY_DIR}/QtCore4.dll" DESTINATION . COMPONENT base)
#install(FILES "${QT_LIBRARY_DIR}/QtGui4.dll" DESTINATION . COMPONENT base)
#install(FILES "${QT_LIBRARY_DIR}/QtXml4.dll" DESTINATION . COMPONENT base)
#
#if(MINGW)
#    get_filename_component(MINGW_DIR ${CMAKE_CXX_COMPILER} PATH)
#    install(FILES "${MINGW_DIR}/mingwm10.dll" DESTINATION . COMPONENT base)
#    install(FILES "${MINGW_DIR}/libgcc_s_dw2-1.dll" DESTINATION . COMPONENT base)
#endif(MINGW)
#
#if(MSVC)
#    #installa il c++ runtime, da verificare se sostituirlo
#    #con l'installer
#	install(FILES "msv_crt/msvcm90.dll" DESTINATION . COMPONENT base)
#	install(FILES "msv_crt/msvcp90.dll" DESTINATION . COMPONENT base)
#	install(FILES "msv_crt/msvcr90.dll" DESTINATION . COMPONENT base)
#	install(FILES "msv_crt/Microsoft.VC90.CRT.manifest" DESTINATION . COMPONENT base)
#	#installa i plugin imageformats
#	install(DIRECTORY "${QT_PLUGINS_DIR}/imageformats" DESTINATION . COMPONENT base  FILES_MATCHING REGEX "q[a-Z]*[^d]4\\.dll")
#endif(MSVC)
#
##install(DIRECTORY Include DESTINATION . COMPONENT dev PATTERN "*svn" EXCLUDE)
##install(DIRECTORY doc DESTINATION . COMPONENT dev PATTERN "*svn" EXCLUDE)
##install(DIRECTORY tests DESTINATION . COMPONENT dev PATTERN "*svn" EXCLUDE)
##install(DIRECTORY Libraries DESTINATION . COMPONENT dev PATTERN "*svn" EXCLUDE)
##install(DIRECTORY resources DESTINATION . COMPONENT dev PATTERN "*svn" EXCLUDE)
##install(DIRECTORY cmake/modules DESTINATION cmake COMPONENT dev PATTERN "*svn" EXCLUDE)
##set(SimplePPP_installFiles
#    #LICENSE
#    #INSTALL.pdf
#    #CMakeLists.txt
#    #SCsimulator.doxyfile
#    #SCsimulatorCONF.xml)
##install(FILES ${SimplePPP_installFiles} DESTINATION . COMPONENT dev)
#
#set(CPACK_PACKAGE_NAME "NMBA Dip switch")
#set(CPACK_PACKAGE_VENDOR "Egicon s.r.l")
#set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "NMBA Dip switch")
#set(CPACK_PACKAGE_VERSION_MAJOR ${NMBA_VERSION_MAJOR})
#set(CPACK_PACKAGE_VERSION_MINOR ${NMBA_VERSION_MINOR})
#set(CPACK_PACKAGE_VERSION_PATCH ${NMBA_VERSION_BUILD})
#set(CPACK_PACKAGE_INSTALL_DIRECTORY "NMBA_Dip_Switch")
#set(CPACK_SYSTEM_NAME "bin")
#set(CPACK_GENERATOR "ZIP")
##set(CPACK_GENERATOR "NSIS")
#
#if(MSVC)	#aggiungi i visual studio redistributables
#	set(CPACK_NSIS_EXTRA_INSTALL_COMMANDS "	ExecWait '\\\"$INSTDIR\\\\vcredist_x86.exe\\\" /q:a' ")
#endif(MSVC)
#
#
##add them to the list of CPack components
#set(CPACK_COMPONENTS_ALL base)
#set(CPACK_COMPONENT_base_DISPLAY_NAME "Required files")
#
#
##this must be the last line
#include(CPack)
